package org.bigk.invoices.services;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.bigk.invoices.exceptions.ServiceException;
import org.bigk.invoices.model.InvoicePosition;

public class InvoicesPositionsServiceImpl implements InvoicesPositionsService {

	private static final Log logger =
		LogFactory.getLog(InvoicesPositionsServiceImpl.class);

	protected InvoicePosition invoicePositionTemplate;
	
	
	public InvoicesPositionsServiceImpl() {
	}

	public InvoicePosition prepareNewInvoicePosition() throws ServiceException {
		if (logger.isDebugEnabled()) {
			logger.debug("prepareNewInvoicePosition() - start");
		}

		InvoicePosition ip = null;
		if (this.invoicePositionTemplate != null) {
			try {
				ip = invoicePositionTemplate.clone();
			} catch (CloneNotSupportedException e) {
				logger.warn("prepareNewInvoice()", e);
			}
		}
		
		if (ip == null) {
			ip = new InvoicePosition();
		}

		if (logger.isDebugEnabled()) {
			logger.debug("prepareNewInvoicePosition() - end - return value=" + ip);
		}
		return ip;
	}

	public InvoicePosition getInvoicePositionTemplate() {
		return invoicePositionTemplate;
	}

	public void setInvoicePositionTemplate(InvoicePosition invoicePositionTemplate) {
		this.invoicePositionTemplate = invoicePositionTemplate;
	}
}
